package cn.edu.scau.cmi.hombio.web.rest;

import cn.edu.scau.cmi.hombio.dao.TaskDAO;
import cn.edu.scau.cmi.hombio.dao.TaskStatusTypeDAO;

import cn.edu.scau.cmi.hombio.domain.Task;
import cn.edu.scau.cmi.hombio.domain.TaskStatusType;

import cn.edu.scau.cmi.hombio.service.TaskStatusTypeService;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Controller;

import org.springframework.web.bind.WebDataBinder;

import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Spring Rest controller that handles CRUD requests for TaskStatusType entities
 * 
 */

@Controller("TaskStatusTypeRestController")

public class TaskStatusTypeRestController {

	/**
	 * DAO injected by Spring that manages Task entities
	 * 
	 */
	@Autowired
	private TaskDAO taskDAO;

	/**
	 * DAO injected by Spring that manages TaskStatusType entities
	 * 
	 */
	@Autowired
	private TaskStatusTypeDAO taskStatusTypeDAO;

	/**
	 * Service injected by Spring that provides CRUD operations for TaskStatusType entities
	 * 
	 */
	@Autowired
	private TaskStatusTypeService taskStatusTypeService;

	/**
	 * Select an existing TaskStatusType entity
	 * 
	 */
	@RequestMapping(value = "/TaskStatusType/{taskstatustype_id}", method = RequestMethod.GET)
	@ResponseBody
	public TaskStatusType loadTaskStatusType(@PathVariable Integer taskstatustype_id) {
		return taskStatusTypeDAO.findTaskStatusTypeByPrimaryKey(taskstatustype_id);
	}

	/**
	* Delete an existing Task entity
	* 
	*/
	@RequestMapping(value = "/TaskStatusType/{taskstatustype_id}/tasks/{task_id}", method = RequestMethod.DELETE)
	@ResponseBody
	public void deleteTaskStatusTypeTasks(@PathVariable Integer taskstatustype_id, @PathVariable Integer related_tasks_id) {
		taskStatusTypeService.deleteTaskStatusTypeTasks(taskstatustype_id, related_tasks_id);
	}

	/**
	* Show all Task entities by TaskStatusType
	* 
	*/
	@RequestMapping(value = "/TaskStatusType/{taskstatustype_id}/tasks", method = RequestMethod.GET)
	@ResponseBody
	public List<Task> getTaskStatusTypeTasks(@PathVariable Integer taskstatustype_id) {
		return new java.util.ArrayList<Task>(taskStatusTypeDAO.findTaskStatusTypeByPrimaryKey(taskstatustype_id).getTasks());
	}

	/**
	* Register custom, context-specific property editors
	* 
	*/
	@InitBinder
	public void initBinder(WebDataBinder binder, HttpServletRequest request) { // Register static property editors.
		binder.registerCustomEditor(java.util.Calendar.class, new org.skyway.spring.util.databinding.CustomCalendarEditor());
		binder.registerCustomEditor(byte[].class, new org.springframework.web.multipart.support.ByteArrayMultipartFileEditor());
		binder.registerCustomEditor(boolean.class, new org.skyway.spring.util.databinding.EnhancedBooleanEditor(false));
		binder.registerCustomEditor(Boolean.class, new org.skyway.spring.util.databinding.EnhancedBooleanEditor(true));
		binder.registerCustomEditor(java.math.BigDecimal.class, new org.skyway.spring.util.databinding.NaNHandlingNumberEditor(java.math.BigDecimal.class, true));
		binder.registerCustomEditor(Integer.class, new org.skyway.spring.util.databinding.NaNHandlingNumberEditor(Integer.class, true));
		binder.registerCustomEditor(java.util.Date.class, new org.skyway.spring.util.databinding.CustomDateEditor());
		binder.registerCustomEditor(String.class, new org.skyway.spring.util.databinding.StringEditor());
		binder.registerCustomEditor(Long.class, new org.skyway.spring.util.databinding.NaNHandlingNumberEditor(Long.class, true));
		binder.registerCustomEditor(Double.class, new org.skyway.spring.util.databinding.NaNHandlingNumberEditor(Double.class, true));
	}

	/**
	* Create a new TaskStatusType entity
	* 
	*/
	@RequestMapping(value = "/TaskStatusType", method = RequestMethod.POST)
	@ResponseBody
	public TaskStatusType newTaskStatusType(@RequestBody TaskStatusType taskstatustype) {
		taskStatusTypeService.saveTaskStatusType(taskstatustype);
		return taskStatusTypeDAO.findTaskStatusTypeByPrimaryKey(taskstatustype.getId());
	}

	/**
	* Save an existing Task entity
	* 
	*/
	@RequestMapping(value = "/TaskStatusType/{taskstatustype_id}/tasks", method = RequestMethod.PUT)
	@ResponseBody
	public Task saveTaskStatusTypeTasks(@PathVariable Integer taskstatustype_id, @RequestBody Task tasks) {
		taskStatusTypeService.saveTaskStatusTypeTasks(taskstatustype_id, tasks);
		return taskDAO.findTaskByPrimaryKey(tasks.getId());
	}

	/**
	* View an existing Task entity
	* 
	*/
	@RequestMapping(value = "/TaskStatusType/{taskstatustype_id}/tasks/{task_id}", method = RequestMethod.GET)
	@ResponseBody
	public Task loadTaskStatusTypeTasks(@PathVariable Integer taskstatustype_id, @PathVariable Integer related_tasks_id) {
		Task task = taskDAO.findTaskByPrimaryKey(related_tasks_id, -1, -1);

		return task;
	}

	/**
	* Delete an existing TaskStatusType entity
	* 
	*/
	@RequestMapping(value = "/TaskStatusType/{taskstatustype_id}", method = RequestMethod.DELETE)
	@ResponseBody
	public void deleteTaskStatusType(@PathVariable Integer taskstatustype_id) {
		TaskStatusType taskstatustype = taskStatusTypeDAO.findTaskStatusTypeByPrimaryKey(taskstatustype_id);
		taskStatusTypeService.deleteTaskStatusType(taskstatustype);
	}

	/**
	* Create a new Task entity
	* 
	*/
	@RequestMapping(value = "/TaskStatusType/{taskstatustype_id}/tasks", method = RequestMethod.POST)
	@ResponseBody
	public Task newTaskStatusTypeTasks(@PathVariable Integer taskstatustype_id, @RequestBody Task task) {
		taskStatusTypeService.saveTaskStatusTypeTasks(taskstatustype_id, task);
		return taskDAO.findTaskByPrimaryKey(task.getId());
	}

	/**
	* Show all TaskStatusType entities
	* 
	*/
	@RequestMapping(value = "/TaskStatusType", method = RequestMethod.GET)
	@ResponseBody
	public List<TaskStatusType> listTaskStatusTypes() {
		return new java.util.ArrayList<TaskStatusType>(taskStatusTypeService.loadTaskStatusTypes());
	}

	/**
	* Save an existing TaskStatusType entity
	* 
	*/
	@RequestMapping(value = "/TaskStatusType", method = RequestMethod.PUT)
	@ResponseBody
	public TaskStatusType saveTaskStatusType(@RequestBody TaskStatusType taskstatustype) {
		taskStatusTypeService.saveTaskStatusType(taskstatustype);
		return taskStatusTypeDAO.findTaskStatusTypeByPrimaryKey(taskstatustype.getId());
	}
}